package com.ruoyi.system.outto.goods.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttrTemplateMapper;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.interAttr.domain.InterAttr;
import com.ruoyi.system.interAttr.mapper.InterAttrMapper;
import com.ruoyi.system.model.domain.*;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.goods.NEWIMMAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/6/14 15:28
 */
@Slf4j
@Service
public class NEWMMAPIImpl implements NEWIMMAPI {

    @Resource
    private GameAttrTemplateMapper gameAttrTemplateMapper;
    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    private ArtRecMapper artRecMapper;
    @Resource
    InterAttrMapper interAttrMapper;

    @Override
    public AjaxResult addAndEditGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> params = params(goodsInfoAndAttrValueDto,salePartner);
        String paramsStr = JSONObject.toJSONString(params);
        log.info("米马添加请求参数：" + paramsStr);
        String response = HttpUtils.sendPost("https://api.mimaapp.cn/v5/goods/publish", paramsStr,"application/json");
        log.info("米马添加返回参数：" +response);
        JSONObject resultJson = JSONObject.parseObject(response);
        Map<String, Object> result = new HashMap<>();
        String data = resultJson.getString("data");
        if (!"0".equals(resultJson.getString("code"))){
            result.put("code",500);
        }else {
            result.put("code",200);
            if(StringUtils.isNotEmpty(JSONObject.parseObject(data).getString("goods_id"))) {
                result.put("outId", String.valueOf(goodsInfoAndAttrValueDto.getId()));
            }

            //因为密码发布有可能是编辑的问题
            //先查询账号信息

            //如果已下架状态开始商家
//            delGame(goodsInfoAndAttrValueDto,1,salePartner);
            //上架
            JSONObject paramss = new JSONObject();
            paramss.put("appid",salePartner.getSaleKey());
            paramss.put("secret",salePartner.getOther());
            paramss.put("action",1);
            paramss.put("out_goods_id",goodsInfoAndAttrValueDto.getId());
            String paramsStrs = JSONObject.toJSONString(paramss);
            log.info("米马上架请求参数：" + paramsStrs);
            String responses = HttpUtils.sendPost("https://api.mimaapp.cn/v5/goods/action", paramsStrs,"application/json");
            log.info("米马下架请求参数：" + responses);
        }

        result.put("req",JSONObject.toJSONString(params));
        result.put("res",response);
        result.put("msg",resultJson.getString("msg"));
        return AjaxResult.success(result);
    }
    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, int action, SalePartner salePartner) {
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        ArtRec artRec = artRecs.get(0);
        JSONObject params = new JSONObject();
        params.put("appid",salePartner.getSaleKey());
        params.put("secret",salePartner.getOther());
        params.put("action",action);
        params.put("out_goods_id",artRec.getOutid());
        String paramsStr = JSONObject.toJSONString(params);
        if(action==1){
            log.info("米马上架请求参数：" + paramsStr);
        }else{
            log.info("米马下架请求参数：" + paramsStr);
        }
        String response = HttpUtils.sendPost("https://api.mimaapp.cn/v5/goods/action", paramsStr,"application/json");
        if(action==1) {
            log.info("米马上架返回参数：" + response);
        }else{
            log.info("米马下架返回参数：" + response);
        }
        JSONObject resultJson = JSONObject.parseObject(response);

        Map<String, Object> result = new HashMap<>();
        if (!"0".equals(resultJson.getString("code"))){
            result.put("code",500);
        }else {
            result.put("code",200);
        }
        artRecMapper.updateArtRec(artRec);
        result.put("req",JSONObject.toJSONString(params));
        result.put("res",response);
        result.put("msg",resultJson.getString("msg"));
        return AjaxResult.success(result);
    }

    private Map<String,Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {

        JSONObject params = new JSONObject();
        params.put("appid", salePartner.getSaleKey());
        params.put("secret", salePartner.getOther());
        String title = goodsInfoAndAttrValueDto.getDes();
        if (goodsInfoAndAttrValueDto.getDes().length() > 150){
            title = goodsInfoAndAttrValueDto.getDes().substring(0,150);
        }
        params.put("title", title);
        params.put("desc",goodsInfoAndAttrValueDto.getDes());
        params.put("account",String.valueOf(System.currentTimeMillis()).substring(4));
        params.put("price",goodsInfoAndAttrValueDto.getPrice());

        //自动匹配属性
        String substring = salePartner.getSaleName().substring(salePartner.getSaleName().indexOf("_")+1);
        InterAttr interAttr = interAttrMapper.selectInterAttrByConfig(substring, goodsInfoAndAttrValueDto.getGameId());
        params.put("game",interAttr.getInterGameId());

        //开始匹配区服属性
        builderServer(goodsInfoAndAttrValueDto, params, interAttr.getServer());
        List<JSONObject> attrs = new ArrayList<>();
        JSONObject properties = new JSONObject();
        if(goodsInfoAndAttrValueDto.getGameName().equals("枪战王者")){
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF2())){
                GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF2()));
                properties.put("VIP等级",gameAttribute1.getFieldName().replace("V","").replace("无","1"));
            }
            attrs.add(properties);
        }else if(goodsInfoAndAttrValueDto.getGameName().equals("永劫无间")){
            properties.put("账号类型",goodsInfoAndAttrValueDto.getServerName().replace("网易","").replace("帐","账"));
            attrs.add(properties);
        }
        //开始匹配单选属性
        builderRadioAttr(goodsInfoAndAttrValueDto, params, interAttr.getRadioAttr(),attrs);
        //开始匹配多选属性
        builderCheckAttr(goodsInfoAndAttrValueDto, params, interAttr.getCheckAttr(),attrs);
        //开始匹配输入框属性
        builderInputAttr(goodsInfoAndAttrValueDto, params, interAttr.getInputAttr(),attrs);

        GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
        goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
        goodsInfoImg.setType(Constants.STR_1);
        List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
        List<Map<String,Object>> imgParam = new ArrayList<>();
        if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getTitleImg())){
            Map<String,Object> imgMap = new HashMap<>();
            imgMap.put("url",goodsInfoAndAttrValueDto.getTitleImg());
            imgParam.add(imgMap);
        }
        if(infoImgs.size()>29){
            infoImgs = infoImgs.subList(0,29);
        }
        for (GoodsInfoImg img : infoImgs) {
            Map<String,Object> imgMap = new HashMap<>();
            imgMap.put("url",img.getImgUrl());
            imgParam.add(imgMap);
        }
        if(CollectionUtils.isEmpty(imgParam)){
            Map<String,Object> imgMap = new HashMap<>();
            imgMap.put("url",goodsInfoAndAttrValueDto.getTitleImg());
            imgParam.add(imgMap);
        }
        params.put("medias", imgParam);
        params.put("out_goods_id",goodsInfoAndAttrValueDto.getId());
        return params;
    }

    /**
     * 开始匹配输入框属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param params
     * @param inputAttr
     */
    private void builderInputAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map params, String inputAttr, List<JSONObject> attrs) {
//        JSONArray propertys = Objects.isNull(params.get("property")) ? new JSONArray() : JSONArray.parseArray(params.get("property").toString());
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();

        //========================开始匹配输入框=====================//
        JSONObject jsonObject1 = JSONObject.parseObject(inputAttr);
        String inputJson = jsonObject1.getString("inputJson");
        List<JSONObject> jsonObjects1 = JSONObject.parseArray(inputJson, JSONObject.class);
        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        ArrayList types = new ArrayList<>();
        types.add("number");
        types.add("input");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> inputTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
        List<JSONObject> defInputObjects = new ArrayList<>();
        defInputObjects.addAll(jsonObjects1);
        for (JSONObject object : jsonObjects1) {
            for (GameAttrTemplate inputTemplate : inputTemplates) {
                JSONObject att = new JSONObject();
                String aavName = inputTemplate.getAavName();
                if (Objects.equals(object.getString("aavName"), inputTemplate.getAavName())) {
                    defInputObjects.remove(object);
                    String aavNameInter = object.getString("interName");
                    String interId = object.getString("interId");
                    for (Field declaredField : declaredFields) {
                        String name = declaredField.getName();
                        if (Objects.equals(aavName, name)) {
                            declaredField.setAccessible(true);
                            Object o = null;
                            try {
                                o = declaredField.get(goodsInfoAndAttrValueDto);
                            } catch (IllegalAccessException e) {
                                throw new GlobalException("3属性参数错误，请匹配后重新配置");
                            }
                            if(Objects.nonNull(o)) {
                                String oneValue = String.valueOf(o);
                                if (StringUtils.isNotEmpty(oneValue)) {
                                    att.put(interId, oneValue);
                                    attrs.add(att);
                                }
                            }
                        }
                    }
                }
            }
        }
        //开始匹配默认值
        for (JSONObject object : defInputObjects) {
            JSONObject att = new JSONObject();
            String defaultValue = object.getString("defaultValue");
            if (StringUtils.isNotEmpty(defaultValue)) {
//                mateMap.put("id", InterConfigId);
//                mateMap.put("val", defaultValue);
                att.put(defaultValue,"1");
                attrs.add(att);
            }
        }
        params.put("attrs", attrs);
    }

    /**
     * 开始匹配多选属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param params
     * @param checkAttr
     */
    private void builderCheckAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map params, String checkAttr, List<JSONObject> attrs) {
//        JSONArray propertys = Objects.isNull(params.get("property")) ? new JSONArray() : JSONArray.parseArray(params.get("property").toString());
        //========================开始匹配多选属性=====================//
        /**
         * 1、先查询自定义中所有多选的字段
         * 2、再查该账号单选字段中的选项
         * 3、再去接口属性匹配表过滤
         */
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();
        JSONObject checkAttrJson = JSONObject.parseObject(checkAttr);
        String interCheckBoxReqs = checkAttrJson.getString("interCheckBoxReqs");
        List<JSONObject> checkJsonList = JSONObject.parseArray(interCheckBoxReqs, JSONObject.class);
        if (org.springframework.util.CollectionUtils.isEmpty(checkAttrJson)) {
            throw new GlobalException("接口多选属性暂未配置");
        }

        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        List<String> types = new ArrayList<>();
        types.add("checkbox");
        types.add("boxradio");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> checkAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);

        for (JSONObject object : checkJsonList) {
            for (GameAttrTemplate attrTemplate : checkAttrTemplates) {
                String aavName = attrTemplate.getAavName();
                for (Field declaredField : declaredFields) {
                    String name = declaredField.getName();
                    if (aavName.equals(name)) {
                        declaredField.setAccessible(true);

                        String ydConfigIdLeveOne = object.getString("YdConfigId");
                        if (StringUtils.isNotEmpty(ydConfigIdLeveOne)) {

                            String[] split2 = ydConfigIdLeveOne.split(",");
                            List<String> list2 = new ArrayList<>();
                            for (String s : split2) {
                                s = s.replace(" ", "");
                                list2.add(s);
                            }
                            if (list2.contains(attrTemplate.getId() + "")) {
                                Object o = null;
                                try {
                                    o = declaredField.get(goodsInfoAndAttrValueDto);
                                } catch (IllegalAccessException e) {
                                    throw new GlobalException("多选项" + attrTemplate.getFieldName() + "匹配错误");
                                }
                                String oneValue = String.valueOf(o);
                                //一级属性
                                String ydConfigId = object.getString("YdConfigId");
                                String InterConfigName = object.getString("InterConfigName");
                                String InterConfigId = object.getString("InterConfigId");
                                if (StringUtils.isNotEmpty(ydConfigId)) {
                                    String[] split = ydConfigId.replace(" ","").split(",");
                                    //一级属性已经匹配，开始匹配二级属性
                                    if (Arrays.asList(split).contains(attrTemplate.getId() + "")) {
                                        String interCheckBoxReqsStr = object.getString("interCheckBoxReqs");
//                                        String interCheckBoxReqsStr = object.getString("interServerRes");
                                        //开始匹配二级属性
                                        List<JSONObject> jsonObjects2 = JSONObject.parseArray(interCheckBoxReqsStr, JSONObject.class);
                                        /**
                                         * 咱们的f字段  多选项都是用空格 隔开，用,号切割数组，跟匹配的数据匹配、匹配上说明此账号勾选的有此属性
                                         */
//                                        List<String> list = new ArrayList<>();
                                        for (JSONObject jsonObject1 : jsonObjects2) {
                                            if (StringUtils.isNotEmpty(oneValue)) {
                                                String[] split1 = oneValue.split(",");
                                                String ydConfigId1 = jsonObject1.getString("YdConfigId");
                                                for (String s : split1) {
                                                    if (Objects.equals(s, ydConfigId1)) {
                                                        String InterConfigId2 = jsonObject1.getString("InterConfigId");
//                                                        list.add(InterConfigId2);
                                                        JSONObject att = new JSONObject();
                                                        att.put(InterConfigId,InterConfigId2);
                                                        attrs.add(att);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    throw new GlobalException("属性参数错误，请匹配后重新配置");
                                }
                            }
                        }
                    }
                }
            }
        }
        params.put("attrs", attrs);
        //========================多选属性匹配完成=====================//
    }

    /**
     * 开始匹配单选属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param params
     * @param radioAttr
     */
    private void builderRadioAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map params, String radioAttr, List<JSONObject> attrs) {
        //========================开始匹配单选属性=====================//
        JSONObject jsonObject = JSONObject.parseObject(radioAttr);
        String interRadioReqs = jsonObject.getString("interRadioReqs");
        log.info(JSONObject.toJSONString(interRadioReqs));
        List<JSONObject> jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
        if (!org.springframework.util.CollectionUtils.isEmpty(jsonObjects)) {
            /**
             * 1、先查询自定义中所有单选的字段
             * 2、再查该账号单选字段中的选项
             * 3、再去接口属性匹配表过滤
             */
            GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
            gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
            gameAttrTemplate.setIsEnable("0");
            gameAttrTemplate.setFieldType("radio");
            List<GameAttrTemplate> gameAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
            Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();


            List<JSONObject> defObjects = new ArrayList<>();
            defObjects.addAll(jsonObjects);
            for (JSONObject object : jsonObjects) {
                for (GameAttrTemplate attrTemplate : gameAttrTemplates) {
                    JSONObject att = new JSONObject();
                    String aavName = attrTemplate.getAavName();
                    for (Field declaredField : declaredFields) {
                        String name = declaredField.getName();
                        if (aavName.equals(name)) {
                            //一级属性
                            //注意 YdConfigId 对应的是 f字段对应的 id
                            if (Objects.equals(object.getLong("YdConfigId"), attrTemplate.getId())) {
                                String InterConfigId = object.getString("InterConfigId");
                                defObjects.remove(object);//如果匹配上，则去掉
                                String interRadioReqs1 = object.getString("interRadioReqs");
                                List<JSONObject> jsonObjects2 = JSONObject.parseArray(interRadioReqs1, JSONObject.class);
                                declaredField.setAccessible(true);
                                try {
                                    //获取选择的值 例如  实名中的可二次
                                    Object o = declaredField.get(goodsInfoAndAttrValueDto);
                                    String oneValue = String.valueOf(o);
                                    List<JSONObject> twoAttr = jsonObjects2.stream().filter(j -> Objects.equals(j.getString("YdConfigId"), oneValue)).collect(Collectors.toList());
                                    String interConfigName = object.getString("InterConfigName");
                                    String defaultValue = object.getString("defaultValue");
                                    if (org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                        if (StringUtils.isNotEmpty(defaultValue)) {
//                                        mateMap.put("id", InterConfigId);
//                                        mateMap.put("val", defaultValue);
                                            att.put(InterConfigId, defaultValue);
                                            attrs.add(att);
                                        }
                                    }
//                                if (org.springframework.util.CollectionUtils.isEmpty(twoAttr) && StringUtils.isEmpty(defaultValue)) {
//                                    throw new GlobalException("属性" + interConfigName + " 接口要求必传，但是暂未匹配到，请设置默认值");
//                                }
                                    if (!org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                        JSONObject jsonObject2 = twoAttr.get(0);
                                        String interConfigId2 = jsonObject2.getString("InterConfigId");
                                        att.put(InterConfigId, interConfigId2);
                                        attrs.add(att);
                                    }
                                } catch (Exception e) {
                                    throw new GlobalException("单选项" + attrTemplate.getFieldName() + "匹配错误");
                                }
                            }
                        }
                    }
                }
            }
            //开始匹配默认值
            for (JSONObject object : defObjects) {
                JSONObject att = new JSONObject();
                String name = object.getString("name");
                interRadioReqs = object.getString("interRadioReqs");
                jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
                for (JSONObject objects : jsonObjects) {
                    if(StringUtils.isNotEmpty(objects.getString("defaultValue"))){
                        att.put(name, objects.getString("defaultValue"));
                        attrs.add(att);
                    }
                }
            }
            params.put("attrs", attrs);
            //========================单选属性匹配结束=====================//
        }
    }

    /**
     * 开始匹配区服属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param params
     * @param server
     */
    private void builderServer(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map params, String server) {
        //========================开始匹配区服属性=====================//
        JSONObject jsonObject = JSONObject.parseObject(server);
        //开始匹配一级区服
        String interServeReqs = jsonObject.getString("interServeReqs");
        String qufuid = "";
        JSONObject oneServerJson = new JSONObject();
        List<JSONObject> oneServer = JSONObject.parseArray(interServeReqs, JSONObject.class);
        String partition = "";
        if (Objects.equals(goodsInfoAndAttrValueDto.getGameType(), "0")) {
            qufuid = goodsInfoAndAttrValueDto.getSystemId() + "" + goodsInfoAndAttrValueDto.getCarrierId() + "";
            for (JSONObject object : oneServer) {
                String ydServeId = object.getString("YdServeId");
                if (StringUtils.isNotEmpty(ydServeId)) {
                    ydServeId = ydServeId.replace(",", "").replace(" ", "");
                    if (qufuid.contains(ydServeId)) {
                        oneServerJson = object;
                        break;
                    }
                }
            }
            partition = oneServerJson.getString("InterServeId");
        } else if (Objects.equals(goodsInfoAndAttrValueDto.getGameName(), "永劫无间")) {
            qufuid = goodsInfoAndAttrValueDto.getGroupId() + "";
            for (JSONObject object : oneServer) {
                String ydServeId = object.getString("YdServeId");
                if (StringUtils.isNotEmpty(ydServeId)) {
                    ydServeId = ydServeId.replace(",", "").replace(" ", "");
                    if (Objects.equals(qufuid, ydServeId)) {
                        oneServerJson = object;
                        break;
                    }
                }
            }
            partition = oneServerJson.getString("InterServeId");
        } else if (Objects.equals(goodsInfoAndAttrValueDto.getGameName(), "无畏契约")) {
            qufuid = goodsInfoAndAttrValueDto.getGroupId() + ""+ goodsInfoAndAttrValueDto.getServerId() + "";
            for (JSONObject object : oneServer) {
                String ydServeId = object.getString("YdServeId");
                if (StringUtils.isNotEmpty(ydServeId)) {
                    ydServeId = ydServeId.replace(",", "").replace(" ", "");
                    if (Objects.equals(qufuid, ydServeId)) {
                        oneServerJson = object;
                        break;
                    }
                }
            }
            partition = oneServerJson.getString("InterServeId");
        } else {
            qufuid = goodsInfoAndAttrValueDto.getGroupId()+"";
            for (JSONObject object : oneServer) {
                String ydServeId = object.getString("YdServeId");
                if (StringUtils.isNotEmpty(ydServeId)) {
                    ydServeId = ydServeId.replace(",", "").replace(" ", "");
                    if (ydServeId.contains(qufuid)) {
                        oneServerJson = object;
                        partition = oneServerJson.getString("InterServeId");
                        String interServerRes = object.getString("interServerRes");
                        oneServer = JSONObject.parseArray(interServerRes, JSONObject.class);
                        qufuid = goodsInfoAndAttrValueDto.getServerId()+"";
                        for(JSONObject objects : oneServer){
                            String ydServeIds = objects.getString("YdServeId");
                            if (StringUtils.isNotEmpty(ydServeIds)) {
                                ydServeIds = ydServeIds.replace(",", "").replace(" ", "");
                                if (Objects.equals(qufuid, ydServeIds)) {
                                    oneServerJson = objects;
                                    partition += " "+oneServerJson.getString("InterServeId");
                                }
                            }
                        }
                    }
                }
            }
        }

        if (Objects.isNull(oneServerJson)) {
            throw new GlobalException("运营商未匹配到");
        }
        params.put("partition", partition);
    }

    private List<GameAttribute> getGameAttributs(String ids) {
        return gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(ids.split(","),
                Long.class));
    }
    private String reIds(String allIds, String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            if (StringUtils.isNotEmpty(allIds)) {
                allIds = allIds + "," + ids;
            } else {
                allIds = ids;
            }
        }
        return allIds;
    }
    /**
     * ys 元神
     * pubg 和平精英
     * wzry 王者荣耀
     * yjwj 永劼无间
     * lolm lol手游
     * lol lol端游~~~~
     */
    private String getEngGameType(String gameName){
        switch (gameName){
            case "王者荣耀":
                return "wzry";
            case "原神":
                return "ys";
            case "和平精英":
                return "pubg";
            case "永劼无间":
                return "yjwj";
            case "英雄联盟手游":
                return "lolm";
            case "英雄联盟":
                return "lol";
            case "穿越火线":
                return "cf";
            case "枪战王者":
                return "cfm";
            case "火影忍者":
                return "hyrz";
            default:
                return null;
        }
    }

    public static void main(String[] args) {
        String string1 = "【有二次实名资格】CF070/山东1区/37V/可排位/幻神+黄忠枪皮/传说辉光/传说暗裔/QBZ-金色蔷薇.黑骑士X2.极光音效卡/雨棠/火麒麟/黑龙/雷神/黑骑士/死神/青龙/朱雀/天龙/毁灭/极光/18枪皮";
        if(!"可".equals(string1.substring(string1.indexOf("V/")+2,string1.indexOf("V/")+3))) {
            log.info(string1.substring(string1.indexOf("排位/") + 3, string1.indexOf("V/")));
        }else{
            log.info(string1.substring(string1.indexOf("区/") + 2, string1.indexOf("V/")));
        }
    }
}